import json

def process_json(json_data, table_name):
    sql_lines = []

    def flatten_json(y):
        out = {}

        def flatten(x, name=''):
            if type(x) is dict:
                for a in x:
                    flatten(x[a], name + a + '_')
            elif type(x) is list:
                i = 0
                for a in x:
                    flatten(a, name + str(i) + '_')
                    i += 1
            else:
                out[name[:-1]] = x

        flatten(y)
        return out

    for item in json_data:
        flattened_item = flatten_json(item)
        columns = ', '.join(flattened_item.keys())
        values = ', '.join([f"'{str(v)}'" for v in flattened_item.values()])
        sql_line = f"INSERT INTO {table_name} ({columns}) VALUES ({values});"
        sql_lines.append(sql_line)

    return sql_lines

# 你的JSON数据
json_data = '''
   [{"name":"线上线索","sort":1,"includeRules":[[{"rules":[{"ruleType":2,"type":3,"actionType":1,"actionId":16,"dimensionRules":[{"id":1244,"dataType":2,"operator":"$include","columnValue":["线上"]}],"metricRules":[]}]}]],"excludeRules":[]},{"name":"线下线索","sort":2,"includeRules":[[{"rules":[{"ruleType":2,"type":3,"actionType":1,"actionId":16,"dimensionRules":[{"id":1244,"dataType":2,"operator":"$include","columnValue":["线下"]}],"metricRules":[]}]}]],"excludeRules":[]}]
'''

table_name = 'your_table_name'
data = json.loads(json_data)
sql_lines = process_json(data, table_name)
for line in sql_lines:
    print(line)
